<template>
  <div class="wx_loginBox">
    <!-- logo -->
    <div class="img">
      <img
        src="https://msmk2019.oss-cn-shanghai.aliyuncs.com/uploads/image/2019pILfAg7Avr1567732916.png"
        alt
      />
    </div>
    <!-- 登录区域 -->
    <div class="yzm">
      <input type="text" v-model="mobile" placeholder="请输入手机号" />
      <span @click="getCode">获取验证码</span>
    </div>
    <input type="text" v-model="sms_code" placeholder="请输入短信用户码" />
    <!-- 找回密码 -->
    <div class="flex">
      <div class="div1">*未注册的手机号将自动注册</div>
      <router-link class="div2" to="/login" tag="div">使用密码登录</router-link>
    </div>
    <!-- 登录 -->
    <div>
      <van-button class="login" @click="smsLogin" color="#fd6b19" size="large" type="warning">登录</van-button>
    </div>
  </div>
</template>

<script>
import {smsCode,login} from '@/request/http.js'

import { Button} from "vant";

export default {
  data(){
    return{
      mobile:'',
      sms_code:''
    }
  },
  components: {
    [Button.name]: Button,
  },
  methods:{
    // 1 获取短信验证码
    getCode(){
      smsCode(this.mobile).then(res=>{
        console.log(res)
      })
    },
    // 2 短信验证码登录
    smsLogin(){
      login(
        this.mobile,
        this.sms_code,
        2,
        1,
      ).then(res=>{
        console.log(res)
        this.$store.commit("add",res)
        localStorage.setItem('adminToken',JSON.stringify(res.remember_token))
        this.$router.push('/index')
      })
    }
  }
};
</script>

<style scoped lang="scss">
.wx_loginBox {
  position: relative;
  min-height:850px; 
  // line-height: 50px;
  background: white;
  .img {
    width: 60%;
    margin: 0 auto;
    padding: 15%;
    img {
      width: 100%;
    }
  }
  .yzm{
    width: 80%;
    height: 56px;
    position: relative;
    span{
      font-size: 12px;
      position: absolute;
      right: -30px;
      top: 14px;
      color: #fd6b19;
    }
  }

  input {
    width: 98%;
    border: none;
    margin: 10px 0;
    height: 30px;
    font-size: 14px;
    color: #c0c0c0;
    box-sizing: border-box;
    padding-left: 40px;
  }
  
  .flex {
    display: flex;
    margin-top: 10px;
    justify-content: space-between;
    width: 94%;
    padding: 0 3%;
    color: gray;
    .div1 {
      font-size: 12px;
      box-sizing: border-box;
      padding-left: 30px;
    }
    .div2 {
      font-size: 12px;
      box-sizing: border-box;
      padding-right: 30px;
    }
  }

  .login {
    width: 80%;
    min-height: 50px;
    position: absolute;
    bottom: 30%;
    left: 10%;
    text-align: center;
    border-radius: 30px;
    overflow: hidden;
  }
}
</style>